
#include <iostream>
#include <vector>
#include <boost/shared_ptr.hpp>

class A
{
  public:
    A(char ch)
    {
        ch_ = ch;
    }

    ~A()
    {
        std::cout << ch_ << "被销毁了!" << std::endl;
    }

    void print()
    {
        std::cout << "print " << ch_ << "!" << std::endl;
    }

  private:
    char ch_;
};

typedef boost::shared_ptr<A> APtr;

int main()
{
    APtr a(new A('a'));
    a->print();
    //delete a;
    a = NULL;

    APtr b(new A('b'));
    b->print();

    APtr c(new A('c'));
    c->print();

    std::vector<APtr> array;
    array.push_back(b);
    array.push_back(c);

    for (int i = 0; i < array.size(); i++)
    {
        APtr tmp = array.at(i);
        tmp->print();
        //delete tmp;
    }

    std::cout << "array长度:" << array.size() << std::endl;
    array.clear();
    std::cout << "array长度:" << array.size() << std::endl;

    printf("程序即将结束!\n");

    return 0;
}